from django.http import HttpResponse ,HttpResponseRedirect
from django.template import RequestContext, loader
from django.utils import simplejson
from social.models import *
from django.db.models import Q


def autocompleteModel(request):
    usersInDB = User.objects.filter(firstName__startswith=request.REQUEST['search']) 
    results = []
    if not usersInDB:
        resp = request.REQUEST['callback'] + '(' + '[""]' + ');'
        return HttpResponse(resp, content_type='application/json')
    for member in usersInDB:
        results.append(member.firstName)
    resp = request.REQUEST['callback'] + '(' + simplejson.dumps(results) + ');'
    return HttpResponse(resp, content_type='application/json')
